//
//  TextLabel.m
//  HealthA段
//
//  Created by MrJXT on 15/6/15.
//  Copyright (c) 2015年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "TextLabel.h"

@implementation TextLabel

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.typewriteTimeInterval = 0.1;
    }
    return self;
}


-(void)startTypewrite
{
    [NSTimer scheduledTimerWithTimeInterval:self.typewriteTimeInterval target:self selector:@selector(outputWord:) userInfo:nil repeats:YES];
}

-(void)outputWord:(id)atimer
{
    if (self.text.length == self.currentIndex) {
        [atimer invalidate];
        atimer = nil;
        
    }else{
        self.currentIndex++;
        NSDictionary *dic = @{NSForegroundColorAttributeName:self.typewriteEffectColor};
        NSMutableAttributedString *mutStr = [[NSMutableAttributedString alloc]initWithString:self.text];
        [mutStr addAttributes:dic range:NSMakeRange(0, self.currentIndex)];
        [self setAttributedText:mutStr];
    }
}
@end
